<!--
 * @Autor: dingxiaolin
 * @Date: 2021-07-18 14:00:10
 * @LastEditors: dingxiaolin
 * @LastEditTime: 2021-07-18 16:04:38
-->
<template>
    <a-radio-group v-model:value="modelValue" v-on="formItem.eventObject" button-style="solid">
        <template v-for="option in formItem.options" :key="option.value">
            <a-radio-button :value="option.value">
                {{ option.label }}
            </a-radio-button>
        </template>
    </a-radio-group>
</template>
<script lang="ts">
import { defineComponent, PropType, computed } from 'vue'
import { Radio } from 'ant-design-vue'

export default defineComponent({
    name: 'SchemaFormRadioButton',
    components: {
        [Radio.Group.name]: Radio.Group,
        [Radio.Button.name]: Radio.Button
    },
    emits: ['update:value'],
    props: {
        formItem: {
            // 表单项
            type: Object as PropType<FormItem>,
            default: () => ({})
        },
        value: undefined as any // 表单项值
    },
    setup(props, { attrs, emit }) {
        const modelValue = computed({
            get: () => props.value,
            set: (val) => emit('update:value', val)
        })

        return {
            modelValue
        }
    }
})
</script>
